<cfcomponent extends="AbsDAO" output="false">

	<cffunction name="create" access="public" returntype="Numeric" output="false">
		<cfargument name="category" type="it.millemultimedia.easyBlog.model.Category" required="true" />	
		<cfset var qry = "" />	
		<cfset var id = 0 />
		
		<cftransaction>
		
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
				INSERT INTO Category
				(
					name,description,uuid
				)
				VALUES
				(
					<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.category.getname()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.category.getdescription()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.category.getuuid()#" null="false" />
				)
			</cfquery>
			
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT MAX(idcategory) AS id
			FROM Category
			</cfquery>
			
			<cfset id = qry.id />
		
		</cftransaction>

		<cfreturn id />
	</cffunction>
	
	<cffunction name="read" access="public" returntype="Query" output="false">
		<cfargument name="category" type="it.millemultimedia.easyBlog.model.Category" required="true" />
		<cfset var qry="" />
		
		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT idcategory,name,description,uuid
			FROM Category
			WHERE idcategory = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.category.getidCategory()#" null="false" />
		</cfquery>
		
		<cfreturn qry />
	</cffunction>
	
	<cffunction name="update" access="public" returntype="void" output="false">
		<cfargument name="category" type="it.millemultimedia.easyBlog.model.Category" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			UPDATE Category
			SET name = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.category.getname()#" null="false" />,
				description = <cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.category.getdescription()#" null="false" />
			WHERE idcategory = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.category.getidCategory()#" null="false" />
		</cfquery>

	</cffunction>
	
	<cffunction name="delete" access="public" returntype="void" output="false">
		<cfargument name="category" type="it.millemultimedia.easyBlog.model.Category" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			DELETE FROM Category
			WHERE idcategory = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.category.getidCategory()#" null="false" />
		</cfquery>
	</cffunction>
	
	
	<cffunction name="list" access="public" returntype="Query" output="false">
		<cfargument name="category" type="it.millemultimedia.easyBlog.model.Category" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT * 
			FROM Category
			WHERE idCategory is NOT NULL 
			<cfif !isNull( arguments.category.getidCategory() ) >
			AND  idCategory = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.category.getidCategory()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.category.getname() ) >
			AND  name = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.category.getname()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.category.getdescription() ) >
			AND  description = <cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.category.getdescription()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.category.getuuid() ) >
			AND  uuid = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.category.getuuid()#" null="false" maxlength="50" />
			</cfif>
			
		</cfquery>
		
		<cfreturn qry/>
	</cffunction>

</cfcomponent>
